<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
	<link rel="stylesheet" href="../css/public.css" media="all">
</head>
<style>
	.layui-card {
		border: 1px solid #f2f2f2;
		border-radius: 5px;
		padding: 16px;
		height: 566px;
	}
	.icon {
		margin-right: 10px;
		color: #1aa094;
	}
	.fa-bullhorn::before {
		content: "\f0a1";
	}
</style>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">

		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<div style="margin: 10px 10px 10px 10px">
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">客户名称</label>
							<div class="layui-input-inline">
								<input type="text" name="clientName" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">客户地址</label>
							<div class="layui-input-inline">
								<input type="text" name="address" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">购买时间</label>
							<div class="layui-input-inline">
								<input type="text" name="createTime" autocomplete="off" class="layui-input rangeDate">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">激活时间</label>
							<div class="layui-input-inline">
								<input type="text" name="useTime" autocomplete="off" class="layui-input rangeDate">
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary" lay-submit
							        lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
							</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>

		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
				<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除</button>
			</div>
		</script>

		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

		<script type="text/html" id="currentTableBar">
			<a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
			<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
		</script>

	</div>
</div>

<div class="layui-card" id="showRemark" style="display: none">
	<div class="layui-card-header"><i class="fa fa-bullhorn icon icon-tip"></i>客户备注</div>
	<div class="layui-card-body layui-text">
		<p id="showInfo"></p>
	</div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'laydate', 'util'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            util = layui.util;

        table.render({
            elem: '#currentTableId',
            url: '/order/list',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 185, title: 'ID', sort: true},
                {field: 'clientName', width: 100, title: '客户名'},
                {field: 'sn', width: 315, title: 'SN'},
                {field: 'phone', width: 135, title: '联系方式'},
                {field: 'email', width: 165, title: '邮箱'},
                {field: 'address', title: '地址', minWidth: 150},
                {field: 'createTime', width: 180, title: '购买时间'},
                {field: 'useTime', width: 180, title: '激活时间'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
        });

        /* 渲染时间选择 */
        laydate.render({
            elem: 'input[name="createTime"]',
            type: 'date',
            range: true,
            trigger: 'click'
        });
        /* 渲染时间选择 */
        laydate.render({
            elem: 'input[name="useTime"]',
            type: 'date',
            range: true,
            trigger: 'click'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var param = data.field;
            if (data.field.createTime) {
                var createTime = data.field.createTime.split(' - ');
                param.minCreateTime = createTime[0];
                param.maxCreateTime = createTime[1];
            } else {
                param.minCreateTime = '';
                param.maxCreateTime = '';
            }
            if (data.field.useTime) {
                var useTime = data.field.useTime.split(' - ');
                param.minUseTime = useTime[0];
                param.maxUseTime = useTime[1];
            } else {
                param.minUseTime = '';
                param.maxUseTime = '';
            }
            param.t = new Date().getTime();
            console.log(param);
            //执行搜索重载
            table.reload('currentTableId', {
                url: '/order/list',
                page: {
                    curr: 1
                }
                , where: param
            });

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    fixed: false,
                    area: ['100%', '100%'],
                    content: '../page/table/edit.html?id=' + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'show') {
                var index = layer.open({
                    type: 1,
	                title: false,
                    anim: 2,
                    fixed: false,
	                area:['400px','600px'],
                    content: $('#showRemark'),
	                success:function () {
                        $("#showInfo").text(data.remark);
                    }
                });
            }
        });

    });
</script>

</body>
</html>
